from selenium import webdriver
import time


# options = webdriver.ChromeOptions()  # 创建option对象
# user_data_dir = r'--user-data-dir=C:\Users\43927\AppData\Local\Google\Chrome\User Data'  # 复制路径 chrome/://version
# options.add_argument(user_data_dir)
#
# driver = webdriver.Chrome(options=options)
# driver.get('https://mail.163.com/js6/main.jsp?sid=sBdXbMoRaasZGygeRoRRkSQTNVGdaglB&df=mail163_letter#module=welcome.WelcomeModule%7C%7B%7D')
#

driver = webdriver.Chrome()
driver.get('https://mail.163.com/')
time.sleep(2)

login_tab = driver.find_element_by_tag_name('iframe')

driver.switch_to.frame(login_tab)
time.sleep(1)

user = driver.find_element_by_xpath('//input[@data-placeholder="邮箱帐号或手机号码"]')
user.send_keys('xuetangwan2023')
time.sleep(1)


password = driver.find_element_by_xpath('//input[@name="password"]')  # 输入密码
password.send_keys('0000000')
time.sleep(1)

login = driver.find_element_by_id("dologin")  # d点击登录
login.click()
time.sleep(1)  # 页面起切换一定记得停一秒


driver.find_element_by_xpath('//*[@id="_mail_component_74_74"]/span[2]').click()  # 点击写信
time.sleep(1)

driver.find_element_by_xpath('//input[@aria-label="收件人地址输入框，请输入邮件地址，多人时地址请以分号隔开"]').send_keys('suncaoren@qq.com')
time.sleep(1)
driver.find_element_by_xpath('//input[@class="nui-ipt-input" and @type="text" and @tabindex="1"]').send_keys('你好帅哥')


# 跳转到输入frame
iframe = driver.find_element_by_class_name('APP-editor-iframe')
driver.switch_to.frame(iframe)


driver.find_element_by_xpath('/html/body').send_keys('nihoashauge') # 输入内容


driver.switch_to.default_content()  # 切回默认窗口

driver.find_element_by_xpath('//*[@class="frame-main-cont-head"]/div/div/div/span[2]').click()


time.sleep(3)

driver.quit()
